//
// Created by Administrator on 2022/1/2 0002.
//
#include <iostream>
#include "t_p.h"

//测试C++指针
void test_pointer(){
    using namespace std;
    int nights = 1001;
    int *pt = new int;
    *pt = 1002;

    cout<<"nights value:"<<nights<<"\t nights addr:"<<&nights<<endl;
    cout<<"pt value:"<<*pt<<"\t pt's addr:"<<pt<<endl;
    //指针本身占用4个字节大小的内存
    cout<<"size of pt:"<<sizeof(pt)<<"\tsize of *pt:"<<sizeof(*pt)<<"\tpt's self addr:"<<&pt<<endl;

    //allowed
    delete pt;
    int hsj = 18;
    int *hsj_p = &hsj;
    //Process finished with exit code -1073741819 (0xC0000005)
    // not allowed ,delete just used in new keywords memery
//    delete hsj_p;


    int *pa = new int[10];
    //释放整个数组，不仅仅是第一个元素
    delete []pa;

    short tell[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    short *p_tell0 = tell;
    short *p_tell0_other = &tell[0];
    short (*ptell)[20] = &tell;
    //读取第2个元素
    cout<<*(p_tell0+1)<<endl;
    cout<<*(p_tell0_other+1)<<endl;
    cout<<*((*ptell)+1)<<endl;
}